package com.wxy.ej.flow.modules.act.service.beanService;

import com.rt.easyjava.common.base.Result;
import com.rt.easyjava.common.base.UserDetailsDto;
import com.rt.easyjava.common.service.BaseV3ServiceImpl;
import com.wxy.ej.flow.modules.act.bean.FormData;
import com.wxy.ej.flow.modules.act.dto.FormDataDto;
import com.wxy.ej.flow.modules.act.repository.mapper.FormDataMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 *  服务实现类
 * @author wuxiaoyong
 * @since 2022-05-20
 */
@Slf4j
@Service(value = "formDataService")
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
public class FormDataService extends BaseV3ServiceImpl<FormDataMapper, FormData, FormDataDto> {
    @Resource
    HttpServletRequest request;

    public Result createBusinessEndNode(FormData formData) {
        formData.setNodeType("EndEvent");
        formData.setNodeName("结束");

        //取登录用户
        UserDetailsDto userDetailsDto = UserDetailsDto.getUserDetailsDto(request.getParameter("userDetailsJson"));
        formData.setCreatorId(Long.parseLong(userDetailsDto.getUserId()));
        formData.setCreator(userDetailsDto.getUserName());
        formData.setUpdatorId(Long.parseLong(userDetailsDto.getUserId()));
        formData.setUpdator(userDetailsDto.getUserName());
        formData.setCompanyId(Long.parseLong(userDetailsDto.getCompanyId()));

        save(formData);
        return Result.builder();
    }
}
